import { NextResponse } from 'next/server'; import { z } from 'zod'; import { chooseCandidate } from '@/lib/ai/scanner'; import { clientIpHash, currentUserId, getAnonId } from '@/lib/ai/request'; export const runtime = 'nodejs'; export async function POST(req: Request, ctx: { params: Promise<{ id: string }> }) { const { id } = await ctx.params; const body = z.object({ assetId: z.string().nullable() }).safeParse(await req.json().catch(() => ({}))); if (!body.success || !/^scan_[a-z0-9]+$/.test(id)) return NextResponse.json({ error: 'Invalid request' }, { status: 400 }); const [userId, anonId, ipHash] = await Promise.all([currentUserId(), getAnonId(false), clientIpHash()]); const ok = await chooseCandidate(id, body.data.assetId, { userId, anonId, ipHash }); if (!ok) return NextResponse.json({ error: 'Not found' }, { status: 404 }); return NextResponse.json({ ok: true }); }